/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * proyectos_usuario.java
 *
 * Created on 21/11/2011, 04:58:21 PM
 */
package scrum.proyectos;

import Procs.ProcsTablero;
import Procs.procs_usuario;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author josema
 */
public class proyectos_usuario extends javax.swing.JFrame {
     String id; 
     ProcsTablero proy=new ProcsTablero();
     
    /** Creates new form proyectos_usuario */
    public proyectos_usuario(String idu) {
        initComponents();
        id=idu;
        llenarform();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(scrum.ScrumApp.class).getContext().getResourceMap(proyectos_usuario.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "", "Proyecto"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(jButton1)
                .addContainerGap(25, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(258, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(244, 244, 244))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(36, 36, 36)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(185, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(162, 162, 162))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void llenarform(){
        procs_usuario resolutividad = new procs_usuario();
        java.sql.ResultSet rs = null;
        java.sql.ResultSet res = null;
        Vector<String> tableHeaders = new Vector<String>();
        Vector tableData = new Vector();
        tableHeaders.add("idp");
        tableHeaders.add("Proyectos");
        tableHeaders.add("Rol");
     
        try 
        {
            rs = resolutividad.verProyectosUsuario(id);
            while (rs.next())
            {
             
               Vector<Object> oneRow = new Vector<Object>();
               oneRow.add(rs.getObject("idProyecto").toString());
               oneRow.add(rs.getObject("nombre").toString());
               oneRow.add(rs.getObject("rn").toString());
               
                   
               
               tableData.add(oneRow);
            }
            jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));
//            T_tipo_usuario.getTableHeader().getColumnModel().getColumn(0).setPreferredWidth(0);
//            T_tipo_usuario.getTableHeader().getColumnModel().getColumn(0).setPreferredWidth(0);
//            T_tipo_usuario.getTableHeader().getColumnModel().getColumn(0).setPreferredWidth(0);
         } catch (SQLException ex) {}
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
         
        if(jTable1.getSelectedRow() >=0){
        
        String idpro= String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), 0));
         String nomp= String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), 1));
         String rol= String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), 2));
         
         datos_proyecto datospro=new datos_proyecto(idpro,nomp,rol);
         datospro.setVisible(true);
        }
        else JOptionPane.showMessageDialog(null, "Primero Debe buscar un proyecto y despues seleccionarlo");
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new proyectos_usuario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
